package com.registry.ser.controller;

import com.registry.ser.instance.ServiceInstance;
import com.registry.ser.request.RegistryParamModel;
import com.registry.ser.service.RegistryParamServiceImpl;
import com.registry.ser.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("registry_centre")
public class RegistryServerController extends BaseService {

    @Autowired
    private RegistryParamServiceImpl registryParamService;

    /**
     * 服务注册
     * @param registryParamModel
     * @return
     */
    @PostMapping("server_registry")
    public ResponseEntity serverRegistry(@RequestBody RegistryParamModel registryParamModel){
        return setResult(registryParamService.serverRegistry(registryParamModel));
    }

    /**
     * 服务下线
     * @param registryParamModel
     * @return
     */
    @PostMapping("server_remove")
    public ResponseEntity serverRemove(@RequestBody RegistryParamModel registryParamModel){
        return setResult(registryParamService.serverRemove(registryParamModel));
    }

    /**
     * 服务续约
     * @param registryParamModel
     * @return
     */
    @PostMapping("server_renewal")
    public ResponseEntity serverRenewal(@RequestBody RegistryParamModel registryParamModel){
        return setResult(registryParamService.serverRenewal(registryParamModel));
    }

    /**
     * 查看该服务集群列表
     * @param registryParamModel
     * @return
     */
    @PostMapping("server_select")
    public List<ServiceInstance> serverSelect(@RequestBody RegistryParamModel registryParamModel){
        return registryParamService.serverSelect(registryParamModel);
    }
}
